using System;
using System.Collections;
using System.Data;
using System.Text;
using System.Windows.Forms;
using ctsu.Admin.BusLogic;
using ctsu.BaseForms;
using ctsu.Security;
using ctsu.Shared;

using ctsu.Data;

namespace ctsu.Admin.Forms
{
	public class FormCoreLabIdentifyBarcode : ctsu.BaseForms.FormBase2
	{
		public event BusinessLogicEvents.BLGridViewEventHandler GridView;

		private BarScan _barscan;
		private BarScan.BarScanCompleteHandler _barScanComplete;

		private FormMain _main;
		private FormInfoBase _formInfo;
		private Permission _formSecurity;

		private Hashtable _configData;
		private FormGrid _fg;

		#region windows controls
		private System.Windows.Forms.GroupBox gbxCheckinType;
		private System.Windows.Forms.Button Retrieve;
		private System.Windows.Forms.TextBox Num_ID;
		private System.Windows.Forms.Label lblNum_ID;
		private System.Windows.Forms.TextBox VisitDate;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.TextBox VisitTime;
		private System.Windows.Forms.Label Date;
		private System.Windows.Forms.TextBox GeneticID;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox PatientName;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox SampleType;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.TextBox Visit;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.TextBox Patient;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.Label label13;
		private System.Windows.Forms.Label label14;
		private System.Windows.Forms.Label label15;
		private System.Windows.Forms.Label label16;
		private System.Windows.Forms.Label label17;
		private System.Windows.Forms.Label label18;
		private System.Windows.Forms.Label label19;
		private System.Windows.Forms.Label label20;
		private System.Windows.Forms.Label label21;
		private System.Windows.Forms.Label label22;
		private System.Windows.Forms.Label label23;
		private System.Windows.Forms.Label label24;
		private System.Windows.Forms.TextBox Note;
		private System.Windows.Forms.TextBox DrawID;
		private System.Windows.Forms.TextBox TestType;
		private System.Windows.Forms.TextBox DBatchInNum;
		private System.Windows.Forms.TextBox DBatchInDate;
		private System.Windows.Forms.TextBox TBatchInDate;
		private System.Windows.Forms.TextBox TBatchInNum;
		private System.Windows.Forms.TextBox Unit;
		private System.Windows.Forms.TextBox NoShow;
		private System.Windows.Forms.TextBox Tester;
		private System.Windows.Forms.TextBox BatchOutDate;
		private System.Windows.Forms.TextBox BatchOutNum;
		private System.Windows.Forms.TextBox IsTest;
		private System.Windows.Forms.TextBox OutTo;
		private System.Windows.Forms.TextBox Result;
		private System.Windows.Forms.TextBox IsLegacy;
		private System.Windows.Forms.TextBox GeneticStudy;
		private System.Windows.Forms.TextBox NotUsed;
		private System.Windows.Forms.Label label25;
		private System.Windows.Forms.TextBox Location;
		private System.Windows.Forms.Label label26;
		private System.Windows.Forms.TextBox Protocol;
		private System.Windows.Forms.Label label27;
		private System.Windows.Forms.TextBox SmallNote;
		private System.Windows.Forms.TextBox OtherID;
		private System.Windows.Forms.Label label28;
		private System.ComponentModel.IContainer components = null;
		#endregion windows controls

		public FormCoreLabIdentifyBarcode(FormMain main, FormInfoBase fi, Permission formSecurity, Hashtable configData)
		{
			InitializeComponent();

			this._main = main;
			GridView += new BaseForms.BusinessLogicEvents.BLGridViewEventHandler(main.OnGridView);

			this._formInfo = fi;
			this._formSecurity = formSecurity;
			this._configData = configData;

			Num_ID.KeyPress += new KeyPressEventHandler(Utils.txtNumWholePos_KeyPress);

			this._barScanComplete += new BarScan.BarScanCompleteHandler(barScan_Complete);
			this._barscan = new BarScan(this, Num_ID, this._barScanComplete);
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose(disposing);
		}

		#region Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormCoreLabIdentifyBarcode));
			this.gbxCheckinType = new System.Windows.Forms.GroupBox();
			this.Retrieve = new System.Windows.Forms.Button();
			this.Num_ID = new System.Windows.Forms.TextBox();
			this.lblNum_ID = new System.Windows.Forms.Label();
			this.VisitDate = new System.Windows.Forms.TextBox();
			this.label7 = new System.Windows.Forms.Label();
			this.VisitTime = new System.Windows.Forms.TextBox();
			this.Date = new System.Windows.Forms.Label();
			this.GeneticID = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.PatientName = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.SampleType = new System.Windows.Forms.TextBox();
			this.label11 = new System.Windows.Forms.Label();
			this.Visit = new System.Windows.Forms.TextBox();
			this.label9 = new System.Windows.Forms.Label();
			this.Patient = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.Protocol = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.DrawID = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.TestType = new System.Windows.Forms.TextBox();
			this.label6 = new System.Windows.Forms.Label();
			this.DBatchInNum = new System.Windows.Forms.TextBox();
			this.label8 = new System.Windows.Forms.Label();
			this.DBatchInDate = new System.Windows.Forms.TextBox();
			this.label10 = new System.Windows.Forms.Label();
			this.TBatchInDate = new System.Windows.Forms.TextBox();
			this.label12 = new System.Windows.Forms.Label();
			this.TBatchInNum = new System.Windows.Forms.TextBox();
			this.label13 = new System.Windows.Forms.Label();
			this.Unit = new System.Windows.Forms.TextBox();
			this.label14 = new System.Windows.Forms.Label();
			this.GeneticStudy = new System.Windows.Forms.TextBox();
			this.label15 = new System.Windows.Forms.Label();
			this.NoShow = new System.Windows.Forms.TextBox();
			this.label16 = new System.Windows.Forms.Label();
			this.Tester = new System.Windows.Forms.TextBox();
			this.label17 = new System.Windows.Forms.Label();
			this.BatchOutDate = new System.Windows.Forms.TextBox();
			this.label18 = new System.Windows.Forms.Label();
			this.BatchOutNum = new System.Windows.Forms.TextBox();
			this.label19 = new System.Windows.Forms.Label();
			this.IsTest = new System.Windows.Forms.TextBox();
			this.label20 = new System.Windows.Forms.Label();
			this.OutTo = new System.Windows.Forms.TextBox();
			this.label21 = new System.Windows.Forms.Label();
			this.Result = new System.Windows.Forms.TextBox();
			this.label22 = new System.Windows.Forms.Label();
			this.IsLegacy = new System.Windows.Forms.TextBox();
			this.label23 = new System.Windows.Forms.Label();
			this.label24 = new System.Windows.Forms.Label();
			this.Note = new System.Windows.Forms.TextBox();
			this.NotUsed = new System.Windows.Forms.TextBox();
			this.label25 = new System.Windows.Forms.Label();
			this.Location = new System.Windows.Forms.TextBox();
			this.label26 = new System.Windows.Forms.Label();
			this.label27 = new System.Windows.Forms.Label();
			this.SmallNote = new System.Windows.Forms.TextBox();
			this.OtherID = new System.Windows.Forms.TextBox();
			this.label28 = new System.Windows.Forms.Label();
			this.pnl2.SuspendLayout();
			this.ButtonGroup.SuspendLayout();
			this.gbxCheckinType.SuspendLayout();
			this.SuspendLayout();
			// 
			// pnl2
			// 
			this.pnl2.Controls.Add(this.OtherID);
			this.pnl2.Controls.Add(this.label28);
			this.pnl2.Controls.Add(this.label27);
			this.pnl2.Controls.Add(this.SmallNote);
			this.pnl2.Controls.Add(this.Location);
			this.pnl2.Controls.Add(this.NotUsed);
			this.pnl2.Controls.Add(this.Note);
			this.pnl2.Controls.Add(this.IsLegacy);
			this.pnl2.Controls.Add(this.Result);
			this.pnl2.Controls.Add(this.OutTo);
			this.pnl2.Controls.Add(this.IsTest);
			this.pnl2.Controls.Add(this.BatchOutDate);
			this.pnl2.Controls.Add(this.BatchOutNum);
			this.pnl2.Controls.Add(this.Tester);
			this.pnl2.Controls.Add(this.NoShow);
			this.pnl2.Controls.Add(this.GeneticStudy);
			this.pnl2.Controls.Add(this.Unit);
			this.pnl2.Controls.Add(this.TBatchInDate);
			this.pnl2.Controls.Add(this.TBatchInNum);
			this.pnl2.Controls.Add(this.DBatchInDate);
			this.pnl2.Controls.Add(this.DBatchInNum);
			this.pnl2.Controls.Add(this.TestType);
			this.pnl2.Controls.Add(this.DrawID);
			this.pnl2.Controls.Add(this.VisitDate);
			this.pnl2.Controls.Add(this.VisitTime);
			this.pnl2.Controls.Add(this.GeneticID);
			this.pnl2.Controls.Add(this.PatientName);
			this.pnl2.Controls.Add(this.SampleType);
			this.pnl2.Controls.Add(this.Visit);
			this.pnl2.Controls.Add(this.Patient);
			this.pnl2.Controls.Add(this.Protocol);
			this.pnl2.Controls.Add(this.label26);
			this.pnl2.Controls.Add(this.label25);
			this.pnl2.Controls.Add(this.label24);
			this.pnl2.Controls.Add(this.label23);
			this.pnl2.Controls.Add(this.label22);
			this.pnl2.Controls.Add(this.label21);
			this.pnl2.Controls.Add(this.label20);
			this.pnl2.Controls.Add(this.label18);
			this.pnl2.Controls.Add(this.label19);
			this.pnl2.Controls.Add(this.label17);
			this.pnl2.Controls.Add(this.label16);
			this.pnl2.Controls.Add(this.label15);
			this.pnl2.Controls.Add(this.label14);
			this.pnl2.Controls.Add(this.label12);
			this.pnl2.Controls.Add(this.label13);
			this.pnl2.Controls.Add(this.label10);
			this.pnl2.Controls.Add(this.label8);
			this.pnl2.Controls.Add(this.label6);
			this.pnl2.Controls.Add(this.label3);
			this.pnl2.Controls.Add(this.label7);
			this.pnl2.Controls.Add(this.Date);
			this.pnl2.Controls.Add(this.label5);
			this.pnl2.Controls.Add(this.label4);
			this.pnl2.Controls.Add(this.label11);
			this.pnl2.Controls.Add(this.label9);
			this.pnl2.Controls.Add(this.label1);
			this.pnl2.Controls.Add(this.label2);
			this.pnl2.Controls.Add(this.gbxCheckinType);
			this.pnl2.Size = new System.Drawing.Size(528, 504);
			// 
			// btnExit
			// 
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.Visible = false;
			// 
			// btnSave
			// 
			this.btnSave.Visible = false;
			// 
			// ButtonGroup
			// 
			this.ButtonGroup.Size = new System.Drawing.Size(632, 40);
			// 
			// btnPrint
			// 
			this.btnPrint.Visible = false;
			// 
			// btnGrid
			// 
			this.btnGrid.Click += new System.EventHandler(this.btnGrid_Click);
			// 
			// gbxCheckinType
			// 
			this.gbxCheckinType.Controls.Add(this.Retrieve);
			this.gbxCheckinType.Controls.Add(this.Num_ID);
			this.gbxCheckinType.Controls.Add(this.lblNum_ID);
			this.gbxCheckinType.Location = new System.Drawing.Point(8, 0);
			this.gbxCheckinType.Name = "gbxCheckinType";
			this.gbxCheckinType.Size = new System.Drawing.Size(232, 56);
			this.gbxCheckinType.TabIndex = 2;
			this.gbxCheckinType.TabStop = false;
			// 
			// Retrieve
			// 
			this.Retrieve.Enabled = false;
			this.Retrieve.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.Retrieve.Location = new System.Drawing.Point(160, 24);
			this.Retrieve.Name = "Retrieve";
			this.Retrieve.Size = new System.Drawing.Size(64, 23);
			this.Retrieve.TabIndex = 43;
			this.Retrieve.Text = "Retrieve";
			this.Retrieve.Click += new System.EventHandler(this.Retrieve_Click);
			// 
			// Num_ID
			// 
			this.Num_ID.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.Num_ID.Location = new System.Drawing.Point(112, 24);
			this.Num_ID.MaxLength = 5;
			this.Num_ID.Name = "Num_ID";
			this.Num_ID.Size = new System.Drawing.Size(40, 20);
			this.Num_ID.TabIndex = 42;
			this.Num_ID.TextChanged += new System.EventHandler(this.Num_ID_TextChanged);
			// 
			// lblNum_ID
			// 
			this.lblNum_ID.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.lblNum_ID.Location = new System.Drawing.Point(8, 16);
			this.lblNum_ID.Name = "lblNum_ID";
			this.lblNum_ID.Size = new System.Drawing.Size(96, 32);
			this.lblNum_ID.TabIndex = 44;
			this.lblNum_ID.Text = "Scan barcode or enter label ID:";
			// 
			// VisitDate
			// 
			this.VisitDate.Location = new System.Drawing.Point(89, 352);
			this.VisitDate.Name = "VisitDate";
			this.VisitDate.ReadOnly = true;
			this.VisitDate.Size = new System.Drawing.Size(160, 20);
			this.VisitDate.TabIndex = 54;
			this.VisitDate.TabStop = false;
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(8, 376);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(48, 16);
			this.label7.TabIndex = 53;
			this.label7.Text = "Time:";
			// 
			// VisitTime
			// 
			this.VisitTime.Location = new System.Drawing.Point(89, 376);
			this.VisitTime.Name = "VisitTime";
			this.VisitTime.ReadOnly = true;
			this.VisitTime.Size = new System.Drawing.Size(160, 20);
			this.VisitTime.TabIndex = 52;
			this.VisitTime.TabStop = false;
			// 
			// Date
			// 
			this.Date.Location = new System.Drawing.Point(8, 352);
			this.Date.Name = "Date";
			this.Date.Size = new System.Drawing.Size(48, 16);
			this.Date.TabIndex = 51;
			this.Date.Text = "Date:";
			// 
			// GeneticID
			// 
			this.GeneticID.Location = new System.Drawing.Point(89, 232);
			this.GeneticID.Name = "GeneticID";
			this.GeneticID.ReadOnly = true;
			this.GeneticID.Size = new System.Drawing.Size(160, 20);
			this.GeneticID.TabIndex = 50;
			this.GeneticID.TabStop = false;
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(8, 232);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(64, 16);
			this.label5.TabIndex = 49;
			this.label5.Text = "Genetic ID:";
			// 
			// PatientName
			// 
			this.PatientName.Location = new System.Drawing.Point(89, 256);
			this.PatientName.Name = "PatientName";
			this.PatientName.ReadOnly = true;
			this.PatientName.Size = new System.Drawing.Size(160, 20);
			this.PatientName.TabIndex = 48;
			this.PatientName.TabStop = false;
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(8, 256);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(80, 16);
			this.label4.TabIndex = 47;
			this.label4.Text = "Patient Name:";
			// 
			// SampleType
			// 
			this.SampleType.Location = new System.Drawing.Point(89, 304);
			this.SampleType.Name = "SampleType";
			this.SampleType.ReadOnly = true;
			this.SampleType.Size = new System.Drawing.Size(160, 20);
			this.SampleType.TabIndex = 46;
			this.SampleType.TabStop = false;
			// 
			// label11
			// 
			this.label11.Location = new System.Drawing.Point(8, 304);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(80, 16);
			this.label11.TabIndex = 45;
			this.label11.Text = "Sample Type:";
			// 
			// Visit
			// 
			this.Visit.Location = new System.Drawing.Point(89, 328);
			this.Visit.Name = "Visit";
			this.Visit.ReadOnly = true;
			this.Visit.Size = new System.Drawing.Size(160, 20);
			this.Visit.TabIndex = 44;
			this.Visit.TabStop = false;
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(8, 328);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(48, 16);
			this.label9.TabIndex = 43;
			this.label9.Text = "Visit:";
			// 
			// Patient
			// 
			this.Patient.Location = new System.Drawing.Point(89, 184);
			this.Patient.Name = "Patient";
			this.Patient.ReadOnly = true;
			this.Patient.Size = new System.Drawing.Size(160, 20);
			this.Patient.TabIndex = 42;
			this.Patient.TabStop = false;
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 184);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(64, 16);
			this.label1.TabIndex = 41;
			this.label1.Text = "Patient ID:";
			// 
			// Protocol
			// 
			this.Protocol.Location = new System.Drawing.Point(89, 160);
			this.Protocol.Name = "Protocol";
			this.Protocol.ReadOnly = true;
			this.Protocol.Size = new System.Drawing.Size(160, 20);
			this.Protocol.TabIndex = 40;
			this.Protocol.TabStop = false;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 160);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(64, 16);
			this.label2.TabIndex = 39;
			this.label2.Text = "Protocol ID:";
			// 
			// DrawID
			// 
			this.DrawID.Location = new System.Drawing.Point(89, 88);
			this.DrawID.Name = "DrawID";
			this.DrawID.ReadOnly = true;
			this.DrawID.Size = new System.Drawing.Size(160, 20);
			this.DrawID.TabIndex = 56;
			this.DrawID.TabStop = false;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(8, 88);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(53, 16);
			this.label3.TabIndex = 55;
			this.label3.Text = "Draw ID:";
			// 
			// TestType
			// 
			this.TestType.Location = new System.Drawing.Point(352, 136);
			this.TestType.Name = "TestType";
			this.TestType.ReadOnly = true;
			this.TestType.Size = new System.Drawing.Size(168, 20);
			this.TestType.TabIndex = 58;
			this.TestType.TabStop = false;
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(262, 140);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(80, 16);
			this.label6.TabIndex = 57;
			this.label6.Text = "Test Type:";
			// 
			// DBatchInNum
			// 
			this.DBatchInNum.Location = new System.Drawing.Point(89, 112);
			this.DBatchInNum.Name = "DBatchInNum";
			this.DBatchInNum.ReadOnly = true;
			this.DBatchInNum.Size = new System.Drawing.Size(160, 20);
			this.DBatchInNum.TabIndex = 60;
			this.DBatchInNum.TabStop = false;
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(8, 112);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(80, 16);
			this.label8.TabIndex = 59;
			this.label8.Text = "Draw Batch In:";
			// 
			// DBatchInDate
			// 
			this.DBatchInDate.Location = new System.Drawing.Point(89, 136);
			this.DBatchInDate.Name = "DBatchInDate";
			this.DBatchInDate.ReadOnly = true;
			this.DBatchInDate.Size = new System.Drawing.Size(160, 20);
			this.DBatchInDate.TabIndex = 62;
			this.DBatchInDate.TabStop = false;
			// 
			// label10
			// 
			this.label10.Location = new System.Drawing.Point(8, 136);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(80, 16);
			this.label10.TabIndex = 61;
			this.label10.Text = "Draw In Date:";
			// 
			// TBatchInDate
			// 
			this.TBatchInDate.Location = new System.Drawing.Point(352, 112);
			this.TBatchInDate.Name = "TBatchInDate";
			this.TBatchInDate.ReadOnly = true;
			this.TBatchInDate.Size = new System.Drawing.Size(168, 20);
			this.TBatchInDate.TabIndex = 66;
			this.TBatchInDate.TabStop = false;
			// 
			// label12
			// 
			this.label12.Location = new System.Drawing.Point(262, 116);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(80, 16);
			this.label12.TabIndex = 65;
			this.label12.Text = "Test In Date:";
			// 
			// TBatchInNum
			// 
			this.TBatchInNum.Location = new System.Drawing.Point(352, 88);
			this.TBatchInNum.Name = "TBatchInNum";
			this.TBatchInNum.ReadOnly = true;
			this.TBatchInNum.Size = new System.Drawing.Size(168, 20);
			this.TBatchInNum.TabIndex = 64;
			this.TBatchInNum.TabStop = false;
			// 
			// label13
			// 
			this.label13.Location = new System.Drawing.Point(262, 92);
			this.label13.Name = "label13";
			this.label13.Size = new System.Drawing.Size(80, 16);
			this.label13.TabIndex = 63;
			this.label13.Text = "Test Batch In:";
			// 
			// Unit
			// 
			this.Unit.Location = new System.Drawing.Point(352, 160);
			this.Unit.Name = "Unit";
			this.Unit.ReadOnly = true;
			this.Unit.Size = new System.Drawing.Size(168, 20);
			this.Unit.TabIndex = 68;
			this.Unit.TabStop = false;
			// 
			// label14
			// 
			this.label14.Location = new System.Drawing.Point(262, 164);
			this.label14.Name = "label14";
			this.label14.Size = new System.Drawing.Size(80, 16);
			this.label14.TabIndex = 67;
			this.label14.Text = "Unit Of Msure:";
			// 
			// GeneticStudy
			// 
			this.GeneticStudy.Location = new System.Drawing.Point(89, 208);
			this.GeneticStudy.Name = "GeneticStudy";
			this.GeneticStudy.ReadOnly = true;
			this.GeneticStudy.Size = new System.Drawing.Size(160, 20);
			this.GeneticStudy.TabIndex = 70;
			this.GeneticStudy.TabStop = false;
			// 
			// label15
			// 
			this.label15.Location = new System.Drawing.Point(8, 208);
			this.label15.Name = "label15";
			this.label15.Size = new System.Drawing.Size(80, 16);
			this.label15.TabIndex = 69;
			this.label15.Text = "Genetic Study:";
			// 
			// NoShow
			// 
			this.NoShow.Location = new System.Drawing.Point(352, 256);
			this.NoShow.Name = "NoShow";
			this.NoShow.ReadOnly = true;
			this.NoShow.Size = new System.Drawing.Size(168, 20);
			this.NoShow.TabIndex = 72;
			this.NoShow.TabStop = false;
			// 
			// label16
			// 
			this.label16.Location = new System.Drawing.Point(262, 260);
			this.label16.Name = "label16";
			this.label16.Size = new System.Drawing.Size(80, 16);
			this.label16.TabIndex = 71;
			this.label16.Text = "No Show:";
			// 
			// Tester
			// 
			this.Tester.Location = new System.Drawing.Point(352, 304);
			this.Tester.Name = "Tester";
			this.Tester.ReadOnly = true;
			this.Tester.Size = new System.Drawing.Size(168, 20);
			this.Tester.TabIndex = 74;
			this.Tester.TabStop = false;
			// 
			// label17
			// 
			this.label17.Location = new System.Drawing.Point(262, 308);
			this.label17.Name = "label17";
			this.label17.Size = new System.Drawing.Size(80, 16);
			this.label17.TabIndex = 73;
			this.label17.Text = "Tester:";
			// 
			// BatchOutDate
			// 
			this.BatchOutDate.Location = new System.Drawing.Point(352, 376);
			this.BatchOutDate.Name = "BatchOutDate";
			this.BatchOutDate.ReadOnly = true;
			this.BatchOutDate.Size = new System.Drawing.Size(168, 20);
			this.BatchOutDate.TabIndex = 78;
			this.BatchOutDate.TabStop = false;
			// 
			// label18
			// 
			this.label18.Location = new System.Drawing.Point(262, 380);
			this.label18.Name = "label18";
			this.label18.Size = new System.Drawing.Size(80, 16);
			this.label18.TabIndex = 77;
			this.label18.Text = "Test Out Date:";
			// 
			// BatchOutNum
			// 
			this.BatchOutNum.Location = new System.Drawing.Point(352, 352);
			this.BatchOutNum.Name = "BatchOutNum";
			this.BatchOutNum.ReadOnly = true;
			this.BatchOutNum.Size = new System.Drawing.Size(168, 20);
			this.BatchOutNum.TabIndex = 76;
			this.BatchOutNum.TabStop = false;
			// 
			// label19
			// 
			this.label19.Location = new System.Drawing.Point(262, 356);
			this.label19.Name = "label19";
			this.label19.Size = new System.Drawing.Size(88, 16);
			this.label19.TabIndex = 75;
			this.label19.Text = "Test Batch Out:";
			// 
			// IsTest
			// 
			this.IsTest.Location = new System.Drawing.Point(352, 280);
			this.IsTest.Name = "IsTest";
			this.IsTest.ReadOnly = true;
			this.IsTest.Size = new System.Drawing.Size(168, 20);
			this.IsTest.TabIndex = 80;
			this.IsTest.TabStop = false;
			// 
			// label20
			// 
			this.label20.Location = new System.Drawing.Point(262, 284);
			this.label20.Name = "label20";
			this.label20.Size = new System.Drawing.Size(88, 16);
			this.label20.TabIndex = 79;
			this.label20.Text = "Test Check-Out:";
			// 
			// OutTo
			// 
			this.OutTo.Location = new System.Drawing.Point(352, 328);
			this.OutTo.Name = "OutTo";
			this.OutTo.ReadOnly = true;
			this.OutTo.Size = new System.Drawing.Size(168, 20);
			this.OutTo.TabIndex = 82;
			this.OutTo.TabStop = false;
			// 
			// label21
			// 
			this.label21.Location = new System.Drawing.Point(262, 332);
			this.label21.Name = "label21";
			this.label21.Size = new System.Drawing.Size(80, 16);
			this.label21.TabIndex = 81;
			this.label21.Text = "Out To:";
			// 
			// Result
			// 
			this.Result.Location = new System.Drawing.Point(352, 208);
			this.Result.Name = "Result";
			this.Result.ReadOnly = true;
			this.Result.Size = new System.Drawing.Size(168, 20);
			this.Result.TabIndex = 84;
			this.Result.TabStop = false;
			// 
			// label22
			// 
			this.label22.Location = new System.Drawing.Point(262, 212);
			this.label22.Name = "label22";
			this.label22.Size = new System.Drawing.Size(80, 16);
			this.label22.TabIndex = 83;
			this.label22.Text = "Test Result:";
			// 
			// IsLegacy
			// 
			this.IsLegacy.Location = new System.Drawing.Point(89, 64);
			this.IsLegacy.Name = "IsLegacy";
			this.IsLegacy.ReadOnly = true;
			this.IsLegacy.Size = new System.Drawing.Size(160, 20);
			this.IsLegacy.TabIndex = 86;
			this.IsLegacy.TabStop = false;
			// 
			// label23
			// 
			this.label23.Location = new System.Drawing.Point(8, 64);
			this.label23.Name = "label23";
			this.label23.Size = new System.Drawing.Size(64, 16);
			this.label23.TabIndex = 85;
			this.label23.Text = "Is Legacy:";
			// 
			// label24
			// 
			this.label24.Location = new System.Drawing.Point(8, 400);
			this.label24.Name = "label24";
			this.label24.Size = new System.Drawing.Size(32, 16);
			this.label24.TabIndex = 87;
			this.label24.Text = "Note:";
			// 
			// Note
			// 
			this.Note.Location = new System.Drawing.Point(88, 400);
			this.Note.Multiline = true;
			this.Note.Name = "Note";
			this.Note.ReadOnly = true;
			this.Note.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.Note.Size = new System.Drawing.Size(432, 80);
			this.Note.TabIndex = 88;
			this.Note.TabStop = false;
			// 
			// NotUsed
			// 
			this.NotUsed.Location = new System.Drawing.Point(352, 232);
			this.NotUsed.Name = "NotUsed";
			this.NotUsed.ReadOnly = true;
			this.NotUsed.Size = new System.Drawing.Size(168, 20);
			this.NotUsed.TabIndex = 90;
			this.NotUsed.TabStop = false;
			// 
			// label25
			// 
			this.label25.Location = new System.Drawing.Point(262, 236);
			this.label25.Name = "label25";
			this.label25.Size = new System.Drawing.Size(80, 16);
			this.label25.TabIndex = 89;
			this.label25.Text = "Not Used:";
			// 
			// Location
			// 
			this.Location.Location = new System.Drawing.Point(352, 184);
			this.Location.Name = "Location";
			this.Location.ReadOnly = true;
			this.Location.Size = new System.Drawing.Size(168, 20);
			this.Location.TabIndex = 92;
			this.Location.TabStop = false;
			// 
			// label26
			// 
			this.label26.Location = new System.Drawing.Point(262, 188);
			this.label26.Name = "label26";
			this.label26.Size = new System.Drawing.Size(80, 16);
			this.label26.TabIndex = 91;
			this.label26.Text = "Location:";
			// 
			// label27
			// 
			this.label27.Location = new System.Drawing.Point(262, 68);
			this.label27.Name = "label27";
			this.label27.Size = new System.Drawing.Size(72, 16);
			this.label27.TabIndex = 94;
			this.label27.Text = "Label Note:";
			// 
			// SmallNote
			// 
			this.SmallNote.Location = new System.Drawing.Point(352, 64);
			this.SmallNote.Name = "SmallNote";
			this.SmallNote.ReadOnly = true;
			this.SmallNote.Size = new System.Drawing.Size(168, 20);
			this.SmallNote.TabIndex = 93;
			this.SmallNote.TabStop = false;
			// 
			// OtherID
			// 
			this.OtherID.Location = new System.Drawing.Point(89, 280);
			this.OtherID.Name = "OtherID";
			this.OtherID.ReadOnly = true;
			this.OtherID.Size = new System.Drawing.Size(160, 20);
			this.OtherID.TabIndex = 96;
			this.OtherID.TabStop = false;
			// 
			// label28
			// 
			this.label28.Location = new System.Drawing.Point(8, 280);
			this.label28.Name = "label28";
			this.label28.Size = new System.Drawing.Size(88, 16);
			this.label28.TabIndex = 95;
			this.label28.Text = "Patient Other ID:";
			// 
			// FormCoreLabIdentifyBarcode
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(632, 590);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "FormCoreLabIdentifyBarcode";
			this.Text = "Core Lab - Barcode Identifier Screen";
			this.Resize += new System.EventHandler(this.FormCoreLabIdentifyBarcode_Resize);
			this.Load += new System.EventHandler(this.FormCoreLabIdentifyBarcode_Load);
			this.pnl2.ResumeLayout(false);
			this.pnl2.PerformLayout();
			this.ButtonGroup.ResumeLayout(false);
			this.gbxCheckinType.ResumeLayout(false);
			this.gbxCheckinType.PerformLayout();
			this.ResumeLayout(false);

		}
		#endregion

		private void barScan_Complete(object sender, BarScanEventArgs e)
		{
			if (e.ID > -1)
				Retrieve_Click(sender, new System.EventArgs());
		}

		private void btnExit_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void FormCoreLabIdentifyBarcode_Load(object sender, System.EventArgs e)
		{

		}

		private void FormCoreLabIdentifyBarcode_Resize(object sender, System.EventArgs e)
		{
			if (this.Height > 410)
				pnl2.Height = this.Height - 46;
			if (this.Width > 464)
				pnl2.Width = this.Width - 2;
		}

		private void Retrieve_Click(object sender, System.EventArgs e)
		{
			Retrieve.Enabled = false;
			Clear();
			GetID();
			Retrieve.Enabled = true;

		}

		private void Clear()
		{
			foreach (Control ctl in pnl2.Controls)
			{
				if (ctl.GetType().ToString() == "System.Windows.Forms.TextBox")
					ctl.Text = "";
			}
		}

		private void GetID()
		{
			if (GetOutID() == 0)
				GetInID();
		}

		private int GetOutID()
		{
			StringBuilder sb = new StringBuilder();

			string sql = "SELECT d.ID, d.Patient, d.Protocol, d.GeneticStudy, " +
				" d.GeneticID, d.BatchInDate, d.BatchInNum, d.VisitDate, " +
				" d.Visit, d.VisitTime, st.Display, t.IsLegacy, " +
				" t.BatchInDate, t.BatchInNum, tt.Display, um.Display, " +
				" t.Location, t.Result, t.NotUsed, t.NoShow, t.IsTestCheckOut, " +
				" tu.Display, t.OutTo, t.BatchOutNum, t.OutDate,t.Note,t.SmallNote " +
				" FROM TestSamples t, DrawSamples d, " +
				" SampleType_L st, TestType_L tt, " +
				" UnitOfMeasure_L um, TestOutTo_L tu " +
				" WHERE t.ID =" + Num_ID.Text +
				" AND d.ID = t.DrawSample " +
				" AND st.ID = d.SampleType " +
				" AND tt.ID = t.TestType " +
				" AND um.ID = t.UnitOfMeasure " +
				" AND tu.ID = t.TestOutTo";


			bool b;
			int retVal = -1;
			string message = "";
			string s = "";
			int patID;
			string patient;

			//SqlConnection conn = LoginForm.GetSqlConnection();
			IDataReader reader = null;
			try
			{
				reader = DataAccess.GetDataReader(sql);
				if (reader.Read())
				{
					this.DrawID.Text = reader.GetInt32(0).ToString("0000");
					patID = reader.GetInt32(1);
					this.Patient.Text = patID.ToString();
					this.Protocol.Text = reader.GetInt32(2).ToString();

					//get patient info
					PatientInfo pi = null;
					patient = "";
					message = "";
					//get the patient info
					pi = CoreLabUtils.GetPatientInfo(patID, out message);
					if (pi.ID == -1)
					{
						MessageBox.Show(this, message, "Patient Information",
							MessageBoxButtons.OK, MessageBoxIcon.Information);
					}
					else
						patient = pi.Name;
					this.PatientName.Text = patient;

					this.OtherID.Text = pi.OtherID;

					b = false;
					if (!reader.IsDBNull(3))
						b = reader.GetBoolean(3);
					s = "";
					if (b)
						s = " X";
					this.GeneticStudy.Text = s;

					s = "";
					if (!reader.IsDBNull(4))
						s = reader.GetString(4);
					this.GeneticID.Text = s;

					s = "";
					if (!reader.IsDBNull(5))
						s = reader.GetDateTime(5).ToShortDateString();
					this.DBatchInDate.Text = s;

					s = "";
					if (!reader.IsDBNull(6))
						s = reader.GetInt32(6).ToString();
					this.DBatchInNum.Text = s;

					s = "";
					if (!reader.IsDBNull(7))
						s = reader.GetDateTime(7).ToShortDateString();
					this.VisitDate.Text = s;

					s = "";
					if (!reader.IsDBNull(8))
						s = reader.GetString(8);
					this.Visit.Text = s;

					s = "";
					if (!reader.IsDBNull(9))
						s = reader.GetString(9);
					this.VisitTime.Text = s;

					s = "";
					if (!reader.IsDBNull(10))
						s = reader.GetString(10);
					this.SampleType.Text = s;

					b = false;
					if (!reader.IsDBNull(11))
						b = reader.GetBoolean(11);
					if (b)
						this.IsLegacy.Text = " X";

					s = "";
					if (!reader.IsDBNull(12))
						s = reader.GetDateTime(12).ToShortDateString();
					this.TBatchInDate.Text = s;

					s = "";
					if (!reader.IsDBNull(13))
						s = reader.GetInt32(13).ToString();
					this.TBatchInNum.Text = s;

					s = "";
					if (!reader.IsDBNull(14))
						s = reader.GetString(14);
					this.TestType.Text = s;

					s = "";
					if (!reader.IsDBNull(15))
						s = reader.GetString(15);
					this.Unit.Text = s;

					s = "";
					if (!reader.IsDBNull(16))
						s = reader.GetString(16);
					this.Location.Text = s;

					s = "";
					if (!reader.IsDBNull(17))
						s = reader.GetString(17);
					this.Result.Text = s;

					b = false;
					if (!reader.IsDBNull(18))
						b = reader.GetBoolean(18);
					if (b)
						this.NotUsed.Text = " X";

					b = false;
					if (!reader.IsDBNull(19))
						b = reader.GetBoolean(19);
					if (b)
						this.NoShow.Text = " X";

					b = false;
					if (!reader.IsDBNull(20))
						b = reader.GetBoolean(20);
					if (b)
						this.IsTest.Text = " X";

					s = "";
					if (!reader.IsDBNull(21))
						s = reader.GetString(21);
					this.Tester.Text = s;

					s = "";
					if (!reader.IsDBNull(22))
						s = reader.GetString(22);
					this.OutTo.Text = s;

					s = "";
					if (!reader.IsDBNull(23))
						s = reader.GetInt32(23).ToString();
					this.BatchOutNum.Text = s;

					s = "";
					if (!reader.IsDBNull(24))
						s = reader.GetDateTime(24).ToShortDateString();
					this.BatchOutDate.Text = s;

					s = "";
					if (!reader.IsDBNull(25))
						s = reader.GetString(25);
					this.Note.Text = s;

					s = "";
					if (!reader.IsDBNull(26))
						s = reader.GetString(26);
					this.SmallNote.Text = s;
					retVal = 1;
				}
				else
					retVal = 0;
			}
			catch (Exception ex)
			{
				sb.Append("Could not retrieve Test ID!");
				sb.Append(Environment.NewLine);
				sb.Append("Error message: " + ex.Message);
				////ExceptionPolicy.HandleException(ex, "Exception Policy");
				MessageBox.Show(this, sb.ToString(), "Retrieve Test ID Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
				retVal = -1;
			}
			finally
			{
				if (reader != null)
				{
					if (!reader.IsClosed)
						reader.Close();
				}
				//if(conn != null)
				//    conn.Dispose();
			}
			return retVal;
		}

		private void GetInID()
		{
			StringBuilder sb = new StringBuilder();

			string sql = "SELECT d.ID, d.Patient, d.Protocol, d.GeneticStudy, " +
				" d.GeneticID, d.BatchInDate, d.BatchInNum, d.VisitDate, " +
				" d.Visit, d.VisitTime, st.Display, t.IsLegacy, " +
				" t.BatchInDate, t.BatchInNum, tt.Display, um.Display, " +
				" t.Location, t.Result, t.NotUsed, t.NoShow,t.Note,t.SmallNote " +
				" FROM TestSamples t, DrawSamples d, " +
				" SampleType_L st, TestType_L tt, " +
				" UnitOfMeasure_L um " +
				" WHERE t.ID =" + Num_ID.Text +
				" AND d.ID = t.DrawSample " +
				" AND st.ID = d.SampleType " +
				" AND tt.ID = t.TestType " +
				" AND um.ID = t.UnitOfMeasure";


			bool b;
			string s;
			string message;
			string patient;
			int patID;

			//SqlConnection conn = LoginForm.GetSqlConnection();
			IDataReader reader = null;
			try
			{
				reader = DataAccess.GetDataReader(sql);
				if (reader.Read())
				{
					this.DrawID.Text = reader.GetInt32(0).ToString("0000");
					patID = reader.GetInt32(1);
					this.Patient.Text = patID.ToString();
					this.Protocol.Text = reader.GetInt32(2).ToString();

					//get patient info
					PatientInfo pi = null;
					patient = "";
					message = "";
					//get the patient info
					pi = CoreLabUtils.GetPatientInfo(patID, out message);
					if (pi.ID == -1)
					{
						MessageBox.Show(this, message, "Patient Information",
							MessageBoxButtons.OK, MessageBoxIcon.Information);
					}
					else
						patient = pi.GetNameOrIdentifier();
					this.PatientName.Text = patient;

					if (reader.IsDBNull(3))
						b = false;
					else
						b = reader.GetBoolean(3);
					s = "";
					if (b)
						s = " X";
					this.GeneticStudy.Text = s;

					s = "";
					if (!reader.IsDBNull(4))
						s = reader.GetString(4);
					this.GeneticID.Text = s;

					s = "";
					if (!reader.IsDBNull(5))
						s = reader.GetDateTime(5).ToShortDateString();
					this.DBatchInDate.Text = s;

					s = "";
					if (!reader.IsDBNull(6))
						s = reader.GetInt32(6).ToString();
					this.DBatchInNum.Text = s;

					s = "";
					if (!reader.IsDBNull(7))
						s = reader.GetDateTime(7).ToShortDateString();
					this.VisitDate.Text = s;

					s = "";
					if (!reader.IsDBNull(8))
						s = reader.GetString(8).ToString();
					this.Visit.Text = s;

					s = "";
					if (!reader.IsDBNull(9))
						s = reader.GetString(9);
					this.VisitTime.Text = s;

					s = "";
					if (!reader.IsDBNull(10))
						s = reader.GetString(10).ToString();
					this.SampleType.Text = s;

					this.IsLegacy.Text = "";
					if (!reader.IsDBNull(11))
						b = reader.GetBoolean(11);
					if (b)
						this.IsLegacy.Text = " X";

					s = "";
					if (!reader.IsDBNull(12))
						s = reader.GetDateTime(12).ToShortDateString();
					this.TBatchInDate.Text = s;

					s = "";
					if (!reader.IsDBNull(13))
						s = reader.GetInt32(13).ToString();
					this.TBatchInNum.Text = s;

					s = "";
					if (!reader.IsDBNull(14))
						s = reader.GetString(14);
					this.TestType.Text = s;

					s = "";
					if (!reader.IsDBNull(15))
						s = reader.GetString(15);
					this.Unit.Text = s;

					s = "";
					if (!reader.IsDBNull(16))
						s = reader.GetString(16);
					this.Location.Text = s;

					s = "";
					if (!reader.IsDBNull(17))
						s = reader.GetString(17);
					this.Result.Text = s;

					this.NotUsed.Text = "";
					b = false;
					if (!reader.IsDBNull(18))
						b = reader.GetBoolean(18);
					if (b)
						this.NotUsed.Text = " X";

					this.NoShow.Text = "";
					b = false;
					if (!reader.IsDBNull(19))
						b = reader.GetBoolean(19);
					if (b)
						this.NoShow.Text = " X";

					s = "";
					if (!reader.IsDBNull(20))
						s = reader.GetString(20);
					this.Note.Text = s;

					s = "";
					if (!reader.IsDBNull(21))
						s = reader.GetString(21);
					this.SmallNote.Text = s;

				}
				else
				{
					sb.Append("Test ID was not found.");
					MessageBox.Show(this, sb.ToString(), "Test ID Not Found",
						MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
					Num_ID.Focus();
				}
			}
			catch (Exception ex)
			{
				sb.Append("Could not retrieve Test ID!");
				sb.Append(Environment.NewLine);
				sb.Append("Error message: " + ex.Message);
				////ExceptionPolicy.HandleException(ex, "Exception Policy");
				MessageBox.Show(this, sb.ToString(), "Retrieve Test ID Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}
			finally
			{
				if (reader != null)
				{
					if (!reader.IsClosed)
						reader.Close();
				}
				//if(conn != null)
				//    conn.Dispose();
			}
		}

		private void Num_ID_TextChanged(object sender, System.EventArgs e)
		{
			if (Num_ID.Text.Length > 0)
			{
				if ((Convert.ToInt32(Num_ID.Text)) > 0)
					Retrieve.Enabled = true;
				else
					Retrieve.Enabled = false;
			}
			else
				Retrieve.Enabled = false;
		}

		private void btnGrid_Click(object sender, System.EventArgs e)
		{
			FormDockingManager fdm = _main.DockManager;

			if (this._fg != null)
			{
				//if its not null then we have already been thru here
				//so just make sure the grid is the active one
				fdm.ActivateDockControl(this._formInfo.TableName);
				return;
			}

			//does the grid exist
			if (fdm.DockControlExists(this._formInfo.TableName))
			{
				//need to get a reference to the formGrid
				_fg = (FormGrid)fdm.GetDockControl(this._formInfo.TableName);
				//make sure it is visible
				if (!fdm.IsDockControlVisible(this._formInfo.TableName))
					fdm.SetDockControlVisibility(this._formInfo.TableName, true);
				//then activate it
				fdm.ActivateDockControl(this._formInfo.TableName);
			}
			else //create it		
			{
				_fg = new FormGrid("SELECT * FROM " + this._formInfo.TableName, this, this._formInfo.TableName);
				_fg.Text = this._formInfo.TableName;
				BLGridViewEventArgs ea = new BLGridViewEventArgs(this._formInfo.TableName, _fg);

				if (GridView != null)
					GridView(this, ea);
				_fg.Show();
			}

		}
	}
}

